# roll_three_dice.py
import plotly.express as px
from die import Die

# 创建三个D6骰子
die1 = Die()
die2 = Die()
die3 = Die()

# 掷骰子并记录结果
results = []
for _ in range(1000):  # 模拟1000次掷骰子
    total = die1.roll() + die2.roll() + die3.roll()
    results.append(total)

# 分析结果
frequencies = {}
for result in results:
    if result in frequencies:
        frequencies[result] += 1
    else:
        frequencies[result] = 1

# 将结果转换为Plotly可以接受的格式
x_values = list(frequencies.keys())
y_values = list(frequencies.values())

# 对结果进行可视化
title = "Results of Rolling Three D6 Dice 1,000 Times"
labels = {'x': 'Sum of Dice', 'y': 'Frequency'}
fig = px.bar(x=x_values, y=y_values, title=title, labels=labels)
fig.show()